package com.molichuxing.services.infrastructure.service.impl;

import com.molichuxing.services.infrastructure.bean.InvoiceDetailBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.InvoiceDetailMapper;
import com.molichuxing.services.infrastructure.dto.response.InvoiceApplyDto;
import com.molichuxing.services.infrastructure.dto.response.InvoiceDetailDto;
import com.molichuxing.services.infrastructure.service.InvoiceDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 发票详情 服务实现类
 * </p>
 *
 * @author zhaopenghui
 * @since 2019-09-11
 */
@Service("invoiceDetailService")
public class InvoiceDetailServiceImpl implements InvoiceDetailService {
    @Autowired
    InvoiceDetailMapper invoiceDetailMapper;

    /**
     * 通过流水号查询发票信息
     *
     * @param invoiceSerialNumber
     * @return
     */
    @Override
    public InvoiceDetailDto getInvoiceDetailBySerialNumber(String invoiceSerialNumber) {
        InvoiceDetailBean invoiceDetailBean = invoiceDetailMapper.getByInvoiceSerialNumber(invoiceSerialNumber);
        return Convert.toInvoiceDetailDto(invoiceDetailBean);
    }

    /**
     * 通过流水号查询发票信息
     *
     * @param list
     * @return
     */
    @Override
    public Map<String, InvoiceDetailDto> getInvoiceDetailMapBySerialNumber(List<String> list) {
        List<InvoiceDetailBean> invoiceDetailBeanList = invoiceDetailMapper.getListByInvoiceSerialNumber(list);
        Map<String, InvoiceDetailDto> invoiceDetailDtoMap = null;
        if (invoiceDetailBeanList != null && invoiceDetailBeanList.size() > 0) {
            List<InvoiceDetailDto> invoiceDetailDtoList = Convert.toInvoiceDetailDtoList(invoiceDetailBeanList);
            invoiceDetailDtoMap = invoiceDetailDtoList.stream().collect(Collectors.toMap(InvoiceDetailDto::getInvoiceSerialNumber, a -> a, (k1, k2) -> k1));
        }
        return invoiceDetailDtoMap;
    }


}
